package com.xc.controller.backend;

import com.xc.common.ServerResponse;
import com.xc.pojo.FundsAppend;
import com.xc.pojo.FundsApply;
import com.xc.service.IFundsAppendService;
import com.xc.service.IFundsApplyService;
import com.xc.service.IUserService;
import com.xc.service.RoleService;
import com.xc.stock.domain.basic.service.UserStaffService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping({"/admin/role/"})
public class AdminRoleController {
    private static final Logger log = LoggerFactory.getLogger(AdminAgentController.class);
    @Autowired
    RoleService roleService;

    //新增权限角色
    @RequestMapping({"insert.do"})
    @ResponseBody
    public ServerResponse insert(@RequestParam(value = "description", defaultValue = "") String description, @RequestParam(value = "name") String name, @RequestParam(value = "purview") String purview) throws Exception {
        return ServerResponse.createBySuccess(this.roleService.insertRole(description, name, purview));
    }

    //更新权限角色
    @RequestMapping({"update.do"})
    @ResponseBody
    public ServerResponse update(@RequestParam(value = "purview", defaultValue = "") String purview, @RequestParam(value = "status",required=false) Integer status, @RequestParam(value = "roleId") Integer roleId, @RequestParam(value = "description",required=false) String description, @RequestParam(value = "name",required=false) String name) {
        return ServerResponse.createBySuccess(this.roleService.updateRole(purview,roleId,status,description,name));
    }

    //删除权限角色
    @RequestMapping({"delete.do"})
    @ResponseBody
    public ServerResponse delete(@RequestParam(value = "roleId") Integer roleId) {
        return ServerResponse.createBySuccess(this.roleService.deleteRole(roleId));
    }

    //用户绑定角色
    @RequestMapping({"banding.do"})
    @ResponseBody
    public ServerResponse banding(@RequestParam(value = "userId") Integer userId,@RequestParam(value = "roleId") Integer roleId) throws Exception  {
        return this.roleService.bandingRole(userId, roleId);
    }

    //角色权限列表
    @RequestMapping({"listByRole.do"})
    @ResponseBody
    public ServerResponse listByRole(@RequestParam(value = "roleId",required=false) Integer roleId) throws Exception  {
        return this.roleService.listByRole(roleId);
    }

    //角色权限
    @RequestMapping({"roleList.do"})
    @ResponseBody
    public ServerResponse roleList() throws Exception  {
        return this.roleService.roleList();
    }

}
